package com.mcp.converter.domain.rule.compatibility.datatype;

import com.mcp.converter.domain.checker.IncompatibilityDetail;
import com.mcp.converter.shared.response.sql.SQLElement;
import com.mcp.converter.domain.rule.compatibility.AbstractDataTypeRule;

/**
 * TIMESTAMP WITH TIME ZONE数据类型兼容性规则
 * OceanBase部分支持TIMESTAMP WITH TIME ZONE数据类型
 *
 * @author zengxiong
 */
public class TimestampWithTimeZoneRule extends AbstractDataTypeRule {

    private static final String RULE_ID = "DT004";
    private static final String RULE_NAME = "TIMESTAMP WITH TIME ZONE数据类型部分兼容";
    private static final String RULE_DESCRIPTION = "OceanBase部分支持TIMESTAMP WITH TIME ZONE数据类型，存在功能限制";

    public TimestampWithTimeZoneRule() {
        super(RULE_ID, RULE_NAME, RULE_DESCRIPTION);
        setIncompatibilityDetail("OceanBase对TIMESTAMP WITH TIME ZONE数据类型的支持存在功能限制",
                "使用TIMESTAMP WITH TIME " + "ZONE" + "数据类型的某些高级功能在OceanBase中可能表现不一致", "建议检查具体使用场景，确保兼容性，或考虑使用TIMESTAMP"
                        + "替代", IncompatibilityDetail.Severity.MEDIUM);
    }

    @Override
    public boolean matches(Object target) {
        if (target instanceof SQLElement) {
            SQLElement element = (SQLElement) target;
            if (isDataTypeElement(element)) {
                String dataTypeName = element.getName().toUpperCase();
                return "TIMESTAMP WITH TIME ZONE".equals(dataTypeName);
            }
        }
        return false;
    }
}
